﻿using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;


namespace Modes
{
    /// <summary>
    /// This Mode is displayed when the program is started and plays a short video in a loop.
    /// </summary>
	public class StartMode : Mode
    {
	    private Video video;
        
	    private VideoPlayer player;

	    private Texture2D videoTexture;

	    public event GlobalGameClasses.Eventhandler.LeaveStartModeHandler leaveStartMode;

        /// <summary>
        /// Plays the video and throws the leaveStartMode event if the user pressed a key
        /// </summary>
	    public override void Update()
        {
            oldKeyboard = keyboard;
            keyboard = Keyboard.GetState();
            if (player.State == MediaState.Stopped)
            {
                player.IsLooped = true;
                player.Play(video);
            }
            if (keyboard.GetPressedKeys().Length != 0)
            {
                player.Stop();
                leaveStartMode();
            }
	    }

        /// <summary>
        /// Draws the current videoframe.
        /// </summary>
	    public override void Draw()
	    {
            videoTexture = player.GetTexture();
            Rectangle dest = new Rectangle(0, 0, spriteBatch.GraphicsDevice.PresentationParameters.BackBufferWidth, spriteBatch.GraphicsDevice.PresentationParameters.BackBufferHeight);
            spriteBatch.Begin();
            spriteBatch.Draw(videoTexture, dest, Color.White);
            spriteBatch.End();
	    }

	    public StartMode(Video video, SpriteBatch spriteBatch)
	    {
            this.video = video;
            player = new VideoPlayer();
            this.spriteBatch = spriteBatch;
	    }

    } 
}

